package com.jingsong.studentapp.adapter;
/*
 * @author zei , QQ:77132995, email:kazeik@163.com
 * 2021-12-17 23:20
 * 类说明:
 */

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.jingsong.studentapp.R;
import com.jingsong.studentapp.lister.OnItemEventListener;
import com.jingsong.studentapp.model.ExamModel;

public class ExamAdapter<A> extends BaseAdapter<A> {
    private OnItemEventListener eventListener;

    public void setEventListener(OnItemEventListener eventListener) {
        this.eventListener = eventListener;
    }

    @Override
    public int getLaoutView() {
        return R.layout.layout_exam;
    }

    @Override
    public void onBindViewHolder(@NonNull KBaseViewHolder holder, int position) {
        LinearLayout llExamItem = (LinearLayout) holder.getViewById(R.id.llExamItem);
        TextView tvExamTitle = (TextView) holder.getViewById(R.id.tvExamTitle);
        TextView tvExamState = (TextView) holder.getViewById(R.id.tvExamState);
        TextView tvGoing = (TextView) holder.getViewById(R.id.tvGoing);
        TextView tvExamTime = (TextView) holder.getViewById(R.id.tvExamTime);
        TextView tvApprColor = (TextView) holder.getViewById(R.id.tvApprColor);

        tvGoing.setOnClickListener(view -> {
            if (null != eventListener) {
                eventListener.onItemEvent(position);
            }
        });

        ExamModel model = (ExamModel) getDatas().get(position);
        tvExamTitle.setText(model.name);
        if (model.state == 0) {
            tvExamState.setText("无考试");
            tvExamState.setTextColor(holder.getContext().getResources().getColor(R.color.gray));
            tvApprColor.setBackground(holder.getContext().getResources().getDrawable(R.drawable.rount_grey_shrap));
            tvExamTime.setVisibility(View.GONE);
            tvGoing.setVisibility(View.GONE);
        } else {
            tvExamTime.setVisibility(View.VISIBLE);
            tvExamTime.setText("考试时间:"+model.times);
            switch (model.state) {
                case 1:
                    tvExamState.setText("考试中");
                    tvGoing.setVisibility(View.VISIBLE);
                    tvExamState.setTextColor(holder.getContext().getResources().getColor(R.color.c24bb95));
                    tvApprColor.setBackground(holder.getContext().getResources().getDrawable(R.drawable.rount_green_shrap));
                    break;
                case 2:
                    tvExamState.setText("候考中");
                    tvGoing.setVisibility(View.GONE);
                    tvExamState.setTextColor(holder.getContext().getResources().getColor(R.color.c24bb95));
                    tvApprColor.setBackground(holder.getContext().getResources().getDrawable(R.drawable.rount_green_shrap));
                    break;
            }
        }
    }
}
